package com.hexiang.rocketmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * rocketmq 消息监听，@RocketMQMessageListener中的selectorExpression为SQL92表达式，默认为*
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "test_sql_filter_spring_topic", consumerGroup = "sql-filter-spring-topic-consumer-group", selectorExpression = "(TAGS is not null and TAGS in ('TagA', 'TagB')) and (a is not null and a between 3 and 5)", selectorType = SelectorType.SQL92)
public class SqlFilterRocketMQListener implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt message) {
        byte[] body = message.getBody();
        String msg = new String(body);
        log.info("接收到过滤消息：topic={},tags={},property[a]={},msg={}", message.getTopic(), message.getTags(), message.getProperty("a"), msg);
    }

}